package com.netty.modbus.dto.response;

import com.netty.modbus.exception.DataConvertException;
import io.netty.buffer.ByteBuf;

/**
 * description: WriteResponseBody <br>
 * date: 2021/10/11 10:38 <br>
 * @author: lwy <br>
 * @version: 1.0 <br>
 */
public class WriteResponseBody extends ResponseBody{


    private final byte[] startAddress=new byte[2];

    private final byte[] quantity=new byte[2];

    private final String devString;

    public WriteResponseBody(String devString) {
        this.devString = devString;
    }

    public String getDevString() {
        return devString;
    }

    @Override
    public void decode(byte[] data) {
        //获取修改的起始地址和修改寄存器数量,起始符（2）+命令字（1）+功能码（2）
        System.arraycopy(data,5,startAddress,0,2);
        System.arraycopy(data,7,quantity,0,2);
    }

    @Override
    public ByteBuf encode() throws DataConvertException {
        return null;
    }

    public byte[] getStartAddress() {
        return startAddress;
    }

    public byte[] getQuantity() {
        return quantity;
    }
}
